import { SEARCH_FOCUS, SEARCH_BLUR, GET_LIST, MOUSE_ENTER, MOUSE_LEAVE, CHEANGR_PAGE } from './constants';
import { fromJS } from 'immutable';
import axios from 'axios';

export const searchFocus = () => ({ type: SEARCH_FOCUS })

export const searchBlur = () => ({ type: SEARCH_BLUR })

export const mouseEnter = () => ({ type: MOUSE_ENTER })

export const mouseLeave = () => ({ type: MOUSE_LEAVE })

export const cheangePage = (page) => ({ type: CHEANGR_PAGE, page })

export const getList = () => {
  return (dispatch) => {
    axios.get('/api/headerList.json').then(({ data }) => {      
      dispatch({
        type: GET_LIST,
        data: fromJS(data),
        totalPage: Math.ceil(data.length / 10)
      })
    })
  }
}